package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.MonitorNote;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeMonitorNote implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,866248053277370,MONITORNOTE,175029,18797874506,4,A,2250.2864,N,11391.5772,E,1.56,149,170721,FDFFFFFF#
        //解密
        String[] split = parseCommand(originalData);
        String imei=split[1];
        String commandNumber=split[3];
        String monitorNum=split[4];//监听人手机号码
        String monitorTime=split[5];//监听时长
        String lat = split[7];
        String lng = split[9];
        String speed = split[11];
        String orientation = split[12];
        String date = split[13];//日月年
        String deviceStatus = split[14];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MonitorNote monitorNote = new MonitorNote();
        monitorNote.setCommandNumber(commandNumber);
        monitorNote.setDeviceDate(date);
        monitorNote.setDeviceTime(commandNumber);
        monitorNote.setPhone(monitorNum);
        monitorNote.setDuration(monitorTime);
        monitorNote.setImei(imei);
        monitorNote.setDeviceStatus(deviceStatus);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        monitorNote.setLocationData(mqLocationData);
        String str="*WT,".concat(imei).concat(",MONITORNOTE,").concat(commandNumber).concat(",MONITORNOTE_GET#");
        return structureMessage(Constants.UPLOAD,Constants.UP_MONITOR_NOTE,true,str,monitorNote);
    }
}
